Ext.define('PJ.view.messagenotification.RemindList', {
    extend: 'AM.default.DefaultList',
    alias: ['widget.remindList'],
    requires: [
               'AM.default.jsonp.DefaultLoadJsonp'
               ],
   selModel: {
       selType: '',
       // 设置为只能通过复选框选中行
       checkOnly: true
   },
    isHavePage: false,
    title:'最新提醒',
    flag:"",
    initComponent: function(){
    	var me= this;
    	this.columns = [{
    		header: '提醒内容',
    		dataIndex: 'remindValue',
    		flex: 1,
    		minWidth: 130,
    		renderer: function(value, meta, record){
    			if (record.get("lookState") == 1)
    				meta.style = "white-space:normal;cursor: pointer;color:blue;";
    			if (record.get("lookState") == 2)
    				meta.style = "white-space:normal;cursor: pointer;color:red;";
                meta.tdAttr = "data-qtip='" + value + "' remindId='"+record.get("remindId")+"'remindUserId='"+record.get("remindUserId")+"'";
    			return value;
    		},
    		listeners: {
    			click: function(g, clm){
    				if(me.flag != "zw"){
    					var remindId = clm.getAttribute("remindId");
    					var remindUserId = clm.getAttribute("remindUserId");
    					win = Ext.create('PJ.view.remindmanagement.View', {
    						title: "查看提醒",
    						grid: me,
    						isReadOnly:true,
    						remindId:remindUserId
    					}).show();
    					var actionName = "load";
    					if(gj_onlineLearning_constant.loadType == "jsonp"){
    						actionName = "loadJsonp";
    					}
    					win.down("form").getForm().doAction(actionName,{
    						url:me.store.viewUrl,
    						params:{
    							searchRemindUserId: remindUserId,
    							remindId: remindId
    						},
    						success:function(f,action){
    							var data = action.response.responseText;
    							var json = gj_onlineLearning_constant.loadType=="ajax" ? Ext.decode(data, true) : action.response;
    							var form = win.down('form');	 
    							var baseForm = form.getForm();
//    							Ext.Ajax.request({
//    								url: showMsgUrl,
////  								url: 'workbench/orchid/data/msgData.jsons',
//    								params: {},
//    								success: function(response){
//    									var data = response.responseText;
//    									var jsonData = Ext.decode(data, true);
//    									var remindUserNoReadCount = jsonData.data.remindUserNoReadCount;
//    									var newsUserNoReadCount = jsonData.data.newsUserNoReadCount;
//    									//me.setTitle("提醒管理("+remindUserNoReadCount+")")
//    									Ext.get("li_"+"8a10e7f9557b199401557b37dfbf0001").dom.innerHTML = '<span class="title"><b class="bull"></b>消息管理('+newsUserNoReadCount+')</span>';	
//    									Ext.get("li_"+"4028809c52207e8a015220860c5r0002").dom.innerHTML = '<span class="title"><b class="bull"></b>提醒管理('+remindUserNoReadCount+')</span>';
//    									$("#newRemind")[0].innerHTML="未读消息"+newsUserNoReadCount+"条，未读提醒"+remindUserNoReadCount+"条&nbsp&nbsp&nbsp&nbsp&nbsp";
//    								}
//    							});
    							me.store.load(function(rec, operation, success){
    								if(rec.length == 0){
    									me.flag = "zw";
    									var model = Ext.create("PJ.model.remindmanagement.List");
    									model.set({
    										"remindValue": "暂无提醒"
    									});
    									rec.push(model);
    									model.commit();//提交model，如果添加此句则列表上不会再显示左上角修改后的标识符
    									store.add(rec)
    								}
    							});
    						}
    					});
    				}
    			}
    		}
    	},{
            header: '提醒类型',
            dataIndex: 'remindType',
            width: 100,
            renderer: function(value, meta, record){
            	meta.tdAttr = "data-qtip='" + value + "'";
            	return value;
            }
        },{
            header: '提醒时间',
            dataIndex: 't.createDate',
            width: 120,
            renderer: function(value, meta, record){
            	meta.tdAttr = "data-qtip='" + value + "'";
            	return value;
            }
        },{
            header: '读取状态',
            dataIndex: 'lookState',
            width: 100,
            renderer: function(value, meta, record){
            	if(value == 1){
            		return "<span style='color:blue'>已读</span>";
            	}else if(value == 2){
            		return "<span style='color:red'>未读</span>";
            	}
            }
        }];
    	
        this.store = Ext.create('PJ.'+ prototype +'.remindmanagement.List',{
        	isLoad: false
        });
        this.callParent(arguments);
        this.loadType = gj_onlineLearning_constant.loadType;//加载方式
    },
    listLoad:function(){
    	var me = this;
        var store = this.store;
        var params = store.proxy.extraParams;
        var newParams = {
        		limit: 5
        };
        Ext.apply(params, newParams);
        store.isLoad = true;
        store.load(function(rec, operation, success){
        	if(rec.length == 0){
        		me.flag = "zw";
        		var model = Ext.create("PJ.model.remindmanagement.List");
        		model.set({
        			"remindValue": "暂无提醒"
        		});
        		rec.push(model);
        		model.commit();//提交model，如果添加此句则列表上不会再显示左上角修改后的标识符
        		store.add(rec)
        	}
        });
	},
    listeners: {
		viewready: function(){
			var me = this;
			var store = this.store;
            var params = store.proxy.extraParams;
            var newParams = {
            		limit: 5
            };
            Ext.apply(params, newParams);
            store.isLoad = true;
            store.load(function(rec, operation, success){
            	if(rec.length == 0){
            		me.flag = "zw";
            		var model = Ext.create("PJ.model.remindmanagement.List");
            		model.set({
            			"remindValue": "暂无提醒"
            		});
            		rec.push(model);
            		model.commit();//提交model，如果添加此句则列表上不会再显示左上角修改后的标识符
            		store.add(rec)
            	}
            });
    		// 触发权限过滤事件
    		this.fireEvent("permission", this);
    		me.timer = setInterval(function(){
    			me.listLoad();
    		},300000);
		}
    }
});
